home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / New System Software Extensions / Thread Manager Extension 1.2 / Interfaces / Threads.p < prev   
Encoding:
Text File  |  1993-09-14  |  5.7 KB  |  192 lines  |  [TEXT/MPS ]

  1. {
  2.     File:        Threads.p
  3.  
  4.     Contains:    External Interface to Thread Manager 1.2
  5.  
  6.     Copyright:    © 1991-1993 by Apple Computer, Inc., all rights reserved.
  7.  
  8.  
  9. }
  10.  
  11. {$IFC UNDEFINED UsingIncludes}
  12. {$SETC UsingIncludes := 0}
  13. {$ENDC}
  14.  
  15. {$IFC NOT UsingIncludes}
  16.     UNIT Threads;
  17.     INTERFACE
  18. {$ENDC}
  19.  
  20. {$IFC UNDEFINED UsingThreads}
  21. {$SETC UsingThreads := 1}
  22.  
  23. {$I+}
  24. {$SETC ThreadsIncludes := UsingIncludes}
  25. {$SETC UsingIncludes := 1}
  26. {$IFC UNDEFINED UsingTypes}
  27. {$I $$Shell(PInterfaces)Types.p}
  28. {$ENDC}
  29. {$IFC UNDEFINED UsingMemory}
  30. {$I $$Shell(PInterfaces)Memory.p}
  31. {$ENDC}
  32. {$SETC UsingIncludes := ThreadsIncludes}
  33.  
  34. {$ENDC}    { UsingThreads }
  35.  
  36. { Thread Gestalt Selectors }
  37. CONST
  38.     gestaltThreadMgrAttr        =        'thds';                { Thread Manager attributes }
  39.     gestaltThreadMgrPresent     =         0;                    { bit true if Thread Mgr is present }
  40.     gestaltSpecificMatchSupport =         1;                    { bit true if Thread Mgr supports exact match creation option }
  41.  
  42. { Thread states }
  43. TYPE
  44.     ThreadState = INTEGER;
  45.  
  46. CONST
  47.     kReadyThreadState    = 0;
  48.     kStoppedThreadState    = 1;
  49.     kRunningThreadState    = 2;
  50.  
  51. { Thread environment characteristics }
  52. TYPE
  53.     ThreadTaskRef = Ptr;
  54.  
  55. { Thread characteristics }
  56. TYPE
  57.     ThreadStyle = LONGINT;
  58.  
  59. CONST
  60.     kCooperativeThread    = 1;
  61.     kPreemptiveThread    = 2;
  62.  
  63. { Thread identifiers }
  64. TYPE
  65.     ThreadID = LONGINT;
  66.  
  67. CONST
  68.     kNoThreadID = 0;
  69.     kCurrentThreadID = 1;
  70.     kApplicationThreadID = 2;
  71.  
  72. { Options when creating a thread }
  73. TYPE
  74.     ThreadOptions = LONGINT;
  75.  
  76. CONST
  77.     kNewSuspend = 1;
  78.     kUsePremadeThread = 2;
  79.     kCreateIfNeeded = 4;
  80.     kFPUNotNeeded = 8;
  81.     kExactMatchThread = 16;
  82.  
  83. { Information supplied to the custom scheduler }
  84. TYPE
  85. SchedulerInfoRecPtr    = ^SchedulerInfoRec;
  86. SchedulerInfoRec    = RECORD
  87.     InfoRecSize:                LONGINT;
  88.     CurrentThreadID:            ThreadID;
  89.     SuggestedThreadID:            ThreadID;
  90.     InterruptedCoopThreadID:    ThreadID;
  91.     END;
  92.  
  93. { Routine proc prototypes }
  94. TYPE
  95.     { Prototype for a thread's entry routine }
  96.     ThreadEntryProcPtr = ProcPtr;            { FUNCTION ThreadMain(threadParam: LONGINT): LONGINT; }
  97.  
  98.     { Prototype for a custom scheduler }
  99.     ThreadSchedulerProcPtr = ProcPtr;        { FUNCTION ThreadScheduler(schedulerInfo: SchedulerInfoRec): ThreadID; }
  100.  
  101.     { Prototype for a custom switcher }
  102.     ThreadSwitchProcPtr = ProcPtr;            { PROCEDURE ThreadSwitcher(threadBeingSwitched: ThreadID; switchProcParam: LONGINT); }
  103.  
  104.     { Prototype for a custom termination notification routine}
  105.     ThreadTerminationProcPtr = ProcPtr;        { PROCEDURE ThreadTerminator(threadTerminated: ThreadID; terminationProcParam: LONGINT); }
  106.  
  107.     { Prototypes for debugger new, dispose & schedule thread notification }
  108.     DebuggerNewThreadProcPtr = ProcPtr;            { PROCEDURE DebuggerNewThread(threadCreated: ThreadID); }
  109.     DebuggerDisposeThreadProcPtr = ProcPtr;        { PROCEDURE DebuggerDisposeThread(threadCreated: ThreadID); }   
  110.     DebuggerThreadSchedulerProcPtr = ProcPtr;    { FUNCTION DebuggerThreadScheduler(schedulerInfo: SchedulerInfoRec): ThreadID; }
  111.  
  112.  
  113. { Errors }
  114. CONST
  115.     threadTooManyReqsErr    = -617;
  116.     threadNotFoundErr        = -618;
  117.     threadProtocolErr        = -619;
  118.  
  119.  
  120. { Thread Manager routines }
  121. FUNCTION CreateThreadPool(threadStyle: ThreadStyle; numToCreate: INTEGER; stackSize: Size):OSErr;
  122.     INLINE $303C,$0501,$ABF2;
  123.  
  124. FUNCTION GetFreeThreadCount(threadStyle: ThreadStyle; VAR freeCount: INTEGER):OSErr;
  125.     INLINE $303C,$0402,$ABF2;
  126.  
  127. FUNCTION GetSpecificFreeThreadCount ( threadStyle: ThreadStyle; stackSize: Size; VAR freeCount: INTEGER):OSErr;
  128.     INLINE $303C,$0615,$ABF2;
  129.     
  130. FUNCTION GetDefaultThreadStackSize(threadStyle: ThreadStyle; VAR stackSize: Size):OSErr;
  131.     INLINE $303C,$0413,$ABF2;
  132.  
  133. FUNCTION ThreadCurrentStackSpace(thread: ThreadID; VAR freeStack: LONGINT):OSErr;
  134.     INLINE $303C,$0414,$ABF2;
  135.  
  136. FUNCTION NewThread(threadStyle: ThreadStyle; threadEntry: ThreadEntryProcPtr; threadParam: LONGINT; stackSize: Size; options: ThreadOptions; threadResult: LongIntPtr; VAR threadMade: ThreadID):OSErr;
  137.     INLINE $303C,$0E03,$ABF2;
  138.  
  139. FUNCTION DisposeThread(threadToDump: ThreadID; threadResult: LONGINT; recycleThread: BOOLEAN):OSErr;
  140.     INLINE $303C,$0504,$ABF2;
  141.  
  142. FUNCTION YieldToThread(suggestedThread: ThreadID):OSErr;
  143.     INLINE $303C,$0205,$ABF2;
  144.  
  145. FUNCTION YieldToAnyThread:OSErr;
  146.     INLINE $42A7,$303C,$0205,$ABF2;
  147.  
  148. FUNCTION GetCurrentThread(VAR currentThreadID: ThreadID):OSErr;
  149.     INLINE $303C,$0206,$ABF2;
  150.  
  151. FUNCTION GetThreadState(threadToGet: ThreadID; VAR threadState: ThreadState):OSErr;
  152.     INLINE $303C,$0407,$ABF2;
  153.  
  154. FUNCTION SetThreadState(threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID):OSErr;
  155.     INLINE $303C,$0508,$ABF2;
  156.  
  157. FUNCTION SetThreadStateEndCritical(threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID):OSErr;
  158.     INLINE $303C,$0512,$ABF2;
  159.  
  160. FUNCTION SetThreadScheduler(threadScheduler: ThreadSchedulerProcPtr):OSErr;
  161.     INLINE $303C,$0209,$ABF2;
  162.  
  163. FUNCTION SetThreadSwitcher(thread: ThreadID; threadSwitcher: ThreadSwitchProcPtr; switchProcParam: LONGINT; inOrOut: BOOLEAN):OSErr;
  164.     INLINE $303C,$070A,$ABF2;
  165.  
  166. FUNCTION SetThreadTerminator(thread: ThreadID; threadTerminator: ThreadTerminationProcPtr; terminationProcParam: LONGINT):OSErr;
  167.     INLINE $303C,$0611,$ABF2;
  168.  
  169. FUNCTION ThreadBeginCritical:OSErr;
  170.     INLINE $303C,$000B,$ABF2;
  171.  
  172. FUNCTION ThreadEndCritical:OSErr;
  173.     INLINE $303C,$000C,$ABF2;
  174.  
  175. FUNCTION SetDebuggerNotificationProcs (    notifyNewThread: DebuggerNewThreadProcPtr;
  176.                                         notifyDisposeThread: DebuggerDisposeThreadProcPtr;
  177.                                         notifyThreadScheduler: DebuggerThreadSchedulerProcPtr ):OSErr;
  178.     INLINE $303C,$060D,$ABF2;
  179.  
  180. FUNCTION GetThreadCurrentTaskRef ( VAR threadTRef: ThreadTaskRef ):OSErr;
  181.     INLINE $303C,$020E,$ABF2;
  182.  
  183. FUNCTION GetThreadStateGivenTaskRef ( threadTRef: ThreadTaskRef; threadToGet: ThreadID; VAR threadState: ThreadState ):OSErr;
  184.     INLINE $303C,$060F,$ABF2;
  185.  
  186. FUNCTION SetThreadReadyGivenTaskRef ( threadTRef: ThreadTaskRef; threadToSet: ThreadID ):OSErr;
  187.     INLINE $303C,$0410,$ABF2;
  188.  
  189. {$IFC NOT UsingIncludes}
  190.     END.
  191. {$ENDC}
  192.